package com.huo.thread.synchronizeddemo;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * 自定义锁
 * 自定义重入锁未实现
 */
public class DefinedLock  implements Lock {

    private boolean isLock;
    @Override
    public synchronized void lock() {
        while (isLock)
            try {
                wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        isLock = true;

    }

    @Override
    public synchronized  void unlock() {
        isLock = false;
        notify();
    }

    @Override
    public void lockInterruptibly() throws InterruptedException {

    }

    @Override
    public boolean tryLock() {
        return false;
    }

    @Override
    public boolean tryLock(long time, TimeUnit unit) throws InterruptedException {
        return false;
    }



    @Override
    public Condition newCondition() {
        return null;
    }
}
